<?php

$getPetInfo = fetch("SELECT * FROM user_pets2 WHERE owner = '$userid' AND id = '$use_on' AND game = '$game'");

if (!$getPetInfo[id])
{
		die("
		<br><center>
		<table width=380 cellspacing=0>
		<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
		</td>
		</tr>
		<tr height=100>
		<td valign=middle>
		<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
		<br>
		<b>$find_item2[item_name]</b>
		</td>
		<td width=300>
		<p 	align=center>That is not your pet.<br>($find_item[parts_left]/$find_item2[parts] Parts Left)<br><a href=myitems.php?game=$game>Back to Items</a></p>
		</td>
		</tr>
		</table>
		</center>
		");
}

if (($find_item2[item_type] != "defence_inc") AND
($find_item2[item_type] != "level_inc") AND
($find_item2[item_type] != "speed_inc") AND
($find_item2[item_type] != "intel_inc") AND
($find_item2[item_type] != "strength_inc"))
{
		die("
		<br><center>
		<table width=380 cellspacing=0>
		<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
		</td>
		</tr>
		<tr height=100>
		<td valign=middle>
		<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
		<br>
		<b>$find_item2[item_name]</b>
		</td>
		<td width=300>
		<p 	align=center>You cannot use that item on your pet.<br>($find_item[parts_left]/$find_item2[parts] Parts Left)<br><a href=myitems.php?game=$game>Back to Items</a></p>
		</td>
		</tr>
		</table>
		</center>
		");
}

if ($find_item2[magic_num] > 1) { $pointNoun = "points"; $levelNoun = "levels"; } else { $pointNoun = "point"; $levelNoun = "level"; }

if ($find_item2[item_type] == "defence_inc")
{
	$newLevel = $getPetInfo[defense]+$find_item2[magic_num];

	mysql_query("UPDATE user_pets2 SET defense=$newLevel WHERE id = '$use_on' AND game = '$game'");

	$effect = "<p>$getPetInfo[name] has gained $find_item2[magic_num] $pointNoun of defense, now it is level $newLevel!</p>";
}

if ($find_item2[item_type] == "level_inc")
{
	$newLevel2 = $getPetInfo[level] + $find_item2[magic_num];
	$newExp = ($newLevel2 * 50) * $newLevel2;

	$effect = "<p>$getPetInfo[name] has gained $find_item2[magic_num] $levelNoun, now it is level $newLevel2! All it's other stats were increased too!</p>";

	$randStrength = rand(1,2) * $find_item2[magic_num];
	$randIntelligence = rand(1,2) * $find_item2[magic_num];
	$randSpeed = rand(1,2) * $find_item2[magic_num];
	$randDefense = rand(1,2) * $find_item2[magic_num];
	$randHP = rand(1,3) * $find_item2[magic_num];

	mysql_query("UPDATE user_pets2 SET level=$newLevel2 WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET experience=$newExp WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET strength=$getPetInfo[strength]+$randStrength WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET intelligence=$getPetInfo[intelligence]+$randIntelligence WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET speed=$getPetInfo[speed]+$randSpeed WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET defense=$getPetInfo[defense]+$randDefense WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET max_hp=$getPetInfo[max_hp]+$randHP WHERE id = '$use_on' AND game = '$game'");
	mysql_query("UPDATE user_pets2 SET current_hp=$getPetInfo[current_hp]+$randHP WHERE id = '$use_on' AND game = '$game'");

	$getPetInfo = fetch("SELECT * FROM user_pets2 WHERE id = '$use_on' AND game = '$game'");
	$effect .= "<p>
	&nbsp;&nbsp;&nbsp;<b>Strength:</B> $getPetInfo[strength]<Br>
	&nbsp;&nbsp;&nbsp;<b>Intelligence:</B> $getPetInfo[intelligence]<Br>
	&nbsp;&nbsp;&nbsp;<b>Speed:</B> $getPetInfo[speed]<Br>
	&nbsp;&nbsp;&nbsp;<b>Defense:</B> $getPetInfo[defense]<Br>
	&nbsp;&nbsp;&nbsp;<b>Health:</B> $getPetInfo[max_hp]
	</p>";
}

if ($find_item2[item_type] == "speed_inc")
{
	$newLevel = $getPetInfo[speed]+$find_item2[magic_num];

	mysql_query("UPDATE user_pets2 SET speed=$newLevel WHERE id = '$use_on' AND game = '$game'");

	$effect = "<p>$getPetInfo[name] has gained $find_item2[magic_num] $pointNoun of speed, now it is level $newLevel!</p>";
}

if ($find_item2[item_type] == "strength_inc")
{
	$newLevel = $getPetInfo[strength]+$find_item2[magic_num];

	mysql_query("UPDATE user_pets2 SET strength=$newLevel WHERE id = '$use_on' AND game = '$game'");

	$effect = "<p>$getPetInfo[name] has gained $find_item2[magic_num] $pointNoun of strength, now it is level $newLevel!</p>";
}

if ($find_item2[item_type] == "intel_inc")
{
	$newLevel = $getPetInfo[intelligence]+$find_item2[magic_num];

	mysql_query("UPDATE user_pets2 SET intelligence=$newLevel WHERE id = '$use_on' AND game = '$game'");

	$effect = "<p>$getPetInfo[name] really liked that book!</p>";
}

if ($find_item[parts_left] <= 1)
{
	mysql_query("DELETE FROM usersitems2 WHERE id = '$id' AND owner = '$userid' AND game = '$game'");
}
else
{
	mysql_query("UPDATE usersitems2 SET parts_left=$find_item[parts_left]-1 WHERE owner = '$userid' AND id = '$id' AND game = '$game'");
}

$minus1 = $find_item[parts_left] - 1;
print "
		<br><center>
		<table width=380 cellspacing=0>
		<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
		</td>
		</tr>
		<tr height=100>
		<td valign=middle>
		<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
		<br>
		<b>$find_item2[item_name]</b>
		</td>
		<td width=300>
		<p 	align=center>$effect<br>($minus1/$find_item2[parts] Parts Left)<br><a href=myitems.php?game=$game>Back to Items</a></p>
		</td>
		</tr>
		</table>
		</center>
";
?>